cd "D:\"
import excel "Data.xlsx", sheet("Data_SecEx") firstrow clear

*Data cleaning
label define Group 0"控制组" 1"政务警告问责" 2"记过问责" 3"记大过问责" 4"降级问责" 5"撤职问责" 6"开除问责"
encode Group, gen(Group1) label(Group)

gen sanction_intensity = 0
replace sanction_intensity = 1 if Group1 == 1 | Group1 == 2 | Group1 == 3
replace sanction_intensity = 2 if Group1 == 4 | Group1 == 5 | Group1 == 6

label define eval1 1"非常不同意" 2"不同意" 3"既不同意也不反对" 4"同意" 5"非常同意"
label define eval2 1"非常不同意" 2"不同意" 3"既不同意也不反对" 4"同意" 5"非常同意"
label define eval3 1"非常不同意" 2"不同意" 3"既不同意也不反对" 4"同意" 5"非常同意"

encode eval1, gen(eval11) label(eval1)
encode eval2, gen(eval21) label(eval2)
encode eval3, gen(eval31) label(eval3)

encoder gender , replace setzero

label define age  1 "0-20岁" 2 "21-30岁" 3 "31-40岁" 4 "41-50岁" 5 "51-60岁" 6 "60岁以上"
encode age, gen(age1) label(age)

label define affiliation 0 "无业" 1 "全日制学生" 2 "党政机关" 3 "事业单位" 4 "国有企业" 5 "私营企业" 6 "外资企业" 7 "个体工商户" 8 "务农"  10"其他"  9"自由职业【提示：如作家、股票投资】"
encode affiliation, gen(affiliation1) label(affiliation)

label define politics 0 "群众" 1 "共青团员" 2 "中共党员" 3 "民主党派"
encode politics , gen(politics1) label(politics)

label define education 0 "小学及以下" 1 "初中" 2 "高中（含中专、技校、职高）" 3  "大专" 4   "大学本科" 5 "硕士" 6"博士"
encode education , gen(education1) label(education)

label define hukou 0 "农业户口" 1 "非农业户口" 2"没有户口"
encode hukou , gen(hukou1) label(hukou)

label define income 1 "5000元以下" 2 "5000-9999元" 3 "10,000-19,999元" 4 "20,000-29,999元" 5 "30,000-39,999元" 6 "40,000-49,999元" 7 "50,000-59,999元" 8 "60,000-79,999元" 9 "80,000-99,999元" 10 "100,000-119,999元" 11 "120,000-139,999元" 12 "140,000-159,999元" 13 "160,000-179,000元" 14 "180,000-199,999元" 15 "200,000-299,999元" 16"30万元以上"
encode income , gen(income1) label(income)

label define Ver2 1"警告" 2"记过" 3"记大过" 4"降级" 5"撤职" 6"开除"
encode Ver2 , gen(Ver21) label(Ver2)

drop age affiliation education politics hukou income eval1 eval2 eval3 Group Ver2
rename (age1 affiliation1 education1 politics1 hukou1 income1 eval11 eval21 eval31 Ver21 Group1) (age affiliation education politics hukou income eval1 eval2 eval3 Ver2 Group)

gen eval = (eval1 + eval2 + eval3 ) / 3

norm eval, method(mmx)
norm satisf, method(mmx)

*Descriptive Statistics
foreach v of var gender age politics income affiliation hukou education{
	logout, save (table_`v') excel replace: tab `v'
}

*Balance check
foreach v of var gender age politics income affiliation hukou education{
	anova `v' sanction_intensity
}

*Modeling
reg mmx_eval i.sanction_intensity
outreg2 using D:\Resultsofexperiment3.xls, replace bdec(3) tdec(3) ctitle(eval) e(r2_a,F) addstat(F test,e(p)) alpha(0.001, 0.01, 0.05)

reg mmx_satisf i.sanction_intensity
outreg2 using D:\Resultsofexperiment3.xls, append bdec(3) tdec(3) ctitle(satisf) e(r2_a,F) addstat(F test,e(p)) alpha(0.001, 0.01, 0.05)

reg mmx_satisf i.sanction_intensity  i.gender i.age i.politics i.income i.affiliation i.hukou i.education
outreg2 using D:\Resultsofexperiment3.xls, append bdec(3) tdec(3) ctitle(satisf) e(r2_a,F) addstat(F test,e(p)) alpha(0.001, 0.01, 0.05)

*Wald test
gen sanction1 = 0
replace sanction1 = 1 if sanction_intensity == 1
gen sanction2 = 0
replace sanction2 = 1 if sanction_intensity == 2
asdoc reg mmx_eval sanction1 sanction2, save(Results of Wald test.doc) replace setstars(***@.001, **@.01, *@.05)
asdoc test sanction1 = sanction2, save(Results of Wald test.doc) 


